package com.java.test.system.depositsettings;

import com.java.test.controller.BaseController;
import com.java.test.dto.PageResultDTO;
import com.java.test.dto.ResponseDTO;
import com.java.test.system.depositsettings.dto.DepositSettingsAddDTO;
import com.java.test.system.depositsettings.dto.DepositSettingsDTO;
import com.java.test.system.depositsettings.dto.DepositSettingsQueryDTO;
import com.java.test.system.depositsettings.dto.DepositSettingsUpdateDTO;
import com.java.test.system.depositsettings.vo.DepositSettingsVO;
import com.java.test.system.dto.LoginAccountInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;

/**
 * 打码设置controller
 *
 * @author lijie1
 * @date 2020/6/29 0029
 */
@Slf4j
@RestController
@RequestMapping("/systemConfig/depositSettings")
public class DepositSettingsController extends BaseController {

    @Autowired
    DepositSettingsService depositSettingsService;

    /**
     * 查询
     * @return
     */
    @RequestMapping(value = "/selectToList",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<DepositSettingsVO>> selectByList(@RequestBody @Valid DepositSettingsQueryDTO queryDTO) {
        log.debug("----------打码设置列表查询----------");
        return depositSettingsService.getSelectByList(queryDTO);
    }

    /**
     * 新增
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public ResponseDTO<String> save(@RequestBody @Valid DepositSettingsAddDTO addDTO, HttpServletRequest request) {
        log.info("----------打码设置添加----------");
        addDTO.setStatus(1);
        addDTO.setCreateTime(new Date());
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-打码设置-打码设置添加");
        addDTO.setOperation(user.getLoginAccout());
        return depositSettingsService.save(addDTO);
    }

    /**
     * 通过id获取数据
     * @param dto
     * @return
     */
    @RequestMapping(value = "/selectById",method = RequestMethod.POST)
    public ResponseDTO<DepositSettingsVO> selectById(@RequestBody @Valid DepositSettingsDTO dto) {
        log.info("----------打码设置查询----------");
        return depositSettingsService.selectById(dto.getId());
    }

    /**
     * 通过id修改数据
     * @param updateDTO
     * @return
     */
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public ResponseDTO<String> updateById(@RequestBody @Valid DepositSettingsUpdateDTO updateDTO, HttpServletRequest request) {
        log.info("----------打码设置修改----------");
        updateDTO.setModifyTime(new Date());
        updateDTO.setStatus(1);
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-打码设置-打码设置修改");
        return depositSettingsService.updateById(updateDTO);
    }

    /**
     * 通过id删除数据
     * @param dto
     * @return
     */
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public ResponseDTO<String> deleteById(@RequestBody @Valid DepositSettingsDTO dto, HttpServletRequest request) {
        log.info("----------打码设置删除----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-打码设置-打码设置删除");
        return depositSettingsService.deleteById(dto.getId());
    }
}
